Nearest neighbour algorithm
data(iris, package = "datasets")
iris_small = iris[sample(nrow(iris), 10), ]
task_small = makeClassifTask(data = iris_small, target = "Species")
lrn = makeLearner("classif.kknn", k = 1)
plotLearnerPrediction(lrn, task_small, features = c("Sepal.Length", "Sepal.Width")) + theme_cowplot()
task = makeClassifTask(data = iris, target = "Species")
lrn = makeLearner("classif.kknn", k = 1)
plotLearnerPrediction(lrn, task, features = c("Sepal.Length", "Sepal.Width")) + theme_cowplot()
# k-Nearest Neighbor. Try changing the number of neighbors and study the effect
lrn = makeLearner("classif.kknn", par.vals = list(k = 7, distance = 2, kernel = "rectangular"))
plotLearnerPrediction(lrn, task, features = c("Sepal.Length", "Sepal.Width")) + theme_cowplot()
# The distance parameter allows you to change the distance measure (as the degree of the Minkowski distance)
lrn = makeLearner("classif.kknn", k = 7, distance = 2)
plotLearnerPrediction(lrn, task, features = c("Sepal.Length", "Sepal.Width")) + theme_cowplot()
# Distance weighting is set by parameter 'kernel'. Rectangle = no weighting, Guassian = gaussian weights,...
lrn = makeLearner("classif.kknn", par.vals = list(k = 7, distance = 2, kernel = "gaussian"))
plotLearnerPrediction(lrn, task, features = c("Sepal.Length", "Sepal.Width")) + theme_cowplot()